/*
 * @Author: 徐博
 * @Date: 2023-02-16 17:29:30
 * @Last Modified by:   徐博
 * @Last Modified time: 2023-02-16 17:29:30
 */

import _axios, {AxiosRequestConfig} from './axios';
import { message } from 'ant-design-vue';
export const request = <T= any>(config: AxiosRequestConfig ): Promise<T> => {
    return new Promise((resolve, reject) => {
        _axios
            .request(config)
            .then(res => {
                console.log(res,'res')
                console.log(config,'config');
                if(config?.responseType) {
                    resolve(res)
                    return;
                }
                // if(res?.code == 200) {
                    resolve(res.data.data);
                // }else {
                //     message.warning(res.msg)
                //     reject(res?.msg);
                // }
            })
            .catch(err => {
                console.log('request fail:', err);
            })
    });
};

const http = {
    get<T = any>(url: string, params ={}, config?: AxiosRequestConfig): Promise<T> {
        return request({url, params, ...config, method: 'GET'})
    },
    post<T = any>(url: string, data = {}, config?: AxiosRequestConfig): Promise<T> {
        return request({url, data, ...config, method: 'POST'})
    }
}

export default http
